package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.backend.SafetyExaminationQuestionBack;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SafetyExaminationQuestion;
import com.ruoyi.system.service.ISafetyExaminationQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题目库Controller
 * 
 * @author ruoyi
 * @date 2021-04-07
 */
@RestController
@RequestMapping("/system/examinationquestion")
public class SafetyExaminationQuestionController extends BaseController
{
    @Autowired
    private ISafetyExaminationQuestionService safetyExaminationQuestionService;

    /**
     * 查询题目库列表
     */
    @PreAuthorize("@ss.hasPermi('system:examquestionbank:list')")
    @GetMapping("/list")
    public TableDataInfo list(SafetyExaminationQuestionBack safetyExaminationQuestionBack)
    {
        List<SafetyExaminationQuestion> list = safetyExaminationQuestionService.selectSafetyExaminationQuestionList(safetyExaminationQuestionBack);
        return getDataTable(list);
    }

    /**
     * 导出题目库列表
     */
    @PreAuthorize("@ss.hasPermi('system:examquestionbank:export')")
    @Log(title = "题目库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SafetyExaminationQuestionBack safetyExaminationQuestionBack)
    {
        List<SafetyExaminationQuestion> list = safetyExaminationQuestionService.selectSafetyExaminationQuestionList(safetyExaminationQuestionBack);
        ExcelUtil<SafetyExaminationQuestion> util = new ExcelUtil<SafetyExaminationQuestion>(SafetyExaminationQuestion.class);
        return util.exportExcel(list, "examinationquestion");
    }

    /**
     * 获取题目库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:examquestionbank:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") String questionId)
    {
        return AjaxResult.success(safetyExaminationQuestionService.selectSafetyExaminationQuestionById(questionId));
    }

    /**
     * 新增题目库
     */
    @PreAuthorize("@ss.hasPermi('system:examquestionbank:add')")
    @Log(title = "题目库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafetyExaminationQuestion safetyExaminationQuestion)
    {
        return toAjax(safetyExaminationQuestionService.insertSafetyExaminationQuestion(safetyExaminationQuestion));
    }

    /**
     * 修改题目库
     */
    @PreAuthorize("@ss.hasPermi('system:examquestionbank:edit')")
    @Log(title = "题目库", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SafetyExaminationQuestion safetyExaminationQuestion)
    {
        return toAjax(safetyExaminationQuestionService.updateSafetyExaminationQuestion(safetyExaminationQuestion));
    }

    /**
     * 删除题目库
     */
    @PreAuthorize("@ss.hasPermi('system:examquestionbank:remove')")
    @Log(title = "题目库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable String[] questionIds)
    {
        return toAjax(safetyExaminationQuestionService.deleteSafetyExaminationQuestionByIds(questionIds));
    }
}
